package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.OrderDto;
import com.itheima.service.OrderSettingService;
import com.itheima.utils.DateUtils;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author cc
 * @Date 2021/8/18 22:05
 * @Version 1.0
 */
@RestController
@RequestMapping("/ordersetting")
public class OrderSettingController {
    @Reference
    private OrderSettingService orderSettingService;

    /**
     * 根据年月查询对应的预约设置数据
     *
     * @param currentDate
     * @return
     */
    @GetMapping("/getOrderSettingByMonth")
    public Result getOrderSettingByMonth(@RequestParam("month") String currentDate) {
        final List<OrderDto> orderSettingByMonth = this.orderSettingService.getOrderSettingByMonth(currentDate);
        if (!ObjectUtils.isEmpty(orderSettingByMonth) && orderSettingByMonth.size() > 0) {
            return new Result(true, MessageConstant.QUERY_ORDER_SUCCESS, orderSettingByMonth);
        }

        return new Result(true, MessageConstant.QUERY_ORDER_FAIL);
    }

   /* public static void main(String[] args) {
        try {
            final List<String> monthBetween = DateUtils.getMonthBetween("2019-03", "2019-03", "MM");
            System.out.println(monthBetween);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }*/
}


